﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using BUS;
using DTO;
using System.Data.OleDb;


namespace CuaHangHoa
{
    public partial class QuanLyDatHang : Form
    {

      //  MatHangDTO mhDTo = new MatHangDTO();
       // HoaDonDTO hdDTO = new HoaDonDTO();

        public QuanLyDatHang()
        {
            InitializeComponent();
        }

        private void QuanLyDatHang_Load(object sender, EventArgs e)
        {
            LoadDSHoa();
            dtpNgayGiao.Format = DateTimePickerFormat.Short;
            dtpNgayGiao.Value = DateTime.Today;
            
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Close();
        }
        public bool IsNumber(string pText)
        {
            Regex regex = new Regex(@"^[-+]?[0-9]*\.?[0-9]+$");
            return regex.IsMatch(pText);
        }


        private bool kiemTraNhap()
        {
            if (!(txtTenKhachHang.Text == "" && txtTenNguoiNhan.Text == "" && txtSDTKhachHang.Text == "" && txtSDTNguoiNhan.Text == "" &&
                txtGiaoDen.Text == "" && DateTime.Compare(dtpNgayGiao.Value, DateTime.Today) >= 0 && txtTraTruoc.Text == "" && txtTongTien.Text == "" &&
                txtConNo.Text == "" && IsNumber(txtSDTKhachHang.Text) == true || IsNumber(txtSDTNguoiNhan.Text) == true &&
                IsNumber(txtTraTruoc.Text) == true && IsNumber(txtTongTien.Text) == true && IsNumber(txtConNo.Text) == true))
            {

                return false;
            }
            return true;
        }

        private void LoadDSHoa()
        {
            QuanLyDatHangBUS qldhBUS = new QuanLyDatHangBUS();
            DataTable dt;
            dt = qldhBUS.layBangMatHang();

            dgvDSHoa.DataSource = dt;
        }

        private void btnDatHang_Click(object sender, EventArgs e)
        {


            if (!kiemTraNhap())
            {
                MessageBox.Show("Dữ liệu nhập vào chưa đúng, vui lòng kiểm tra lại.");
            }
            else
            {
                MessageBox.Show("kakak");

            }

        }

        private void dgvDSHoa_SelectionChanged(object sender, EventArgs e)
        {
             if(this.dgvDSHoa.SelectedCells.Count>0 && !(this.dgvDSHoa.SelectedCells[0].RowIndex == this.dgvDSHoa.RowCount-1)){
                



             
             
             }

        }

        private void dgvDSHoa_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.dgvDSHoa.SelectedCells.Count > 0 && !(this.dgvDSHoa.SelectedCells[0].RowIndex == this.dgvDSHoa.RowCount - 1))
            {






            }
        }

        private void btnLamMoi_Click(object sender, EventArgs e)
        {
            txtTenKhachHang.Text = "" ;
            txtTenNguoiNhan.Text = "" ;
            txtSDTKhachHang.Text = "" ;
            txtSDTNguoiNhan.Text ="" ;
            txtGiaoDen.Text = "" ;
            dtpNgayGiao.Value = DateTime.Today ;
            txtTraTruoc.Text = "" ;
            txtTongTien.Text = "" ;
            txtConNo.Text = "" ;
            txtGhiChu.Text = "" ;
        }

      
     
    }
       
}
